{{- $url := .Site.Params.cveFeedBucket }}
{{- $feed := "" -}}
<!-- Try to fetch remote resource from the specified URL -->
{{- with resources.GetRemote $url -}}
  {{- if .Err -}}
    <!-- Error message if retrieval fails -->
    {{- $message := printf "Failed to retrieve CVE data: %s" .Err -}}
    {{- if eq hugo.Environment "production" -}}
      {{- errorf $message -}}
    {{- else -}}
      {{- warnf $message -}}
    {{- end -}}
  {{- else -}}
    <!-- Process the content if retrieval is successful -->
    {{- $feed = .Content | transform.Unmarshal -}}
    {{- if ne $feed.version "https://jsonfeed.org/version/1.1" -}}
      {{- $warningMessage := "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." -}}
      {{- if eq hugo.Environment "production" -}}
        {{- errorf $warningMessage -}}
      {{- else -}}
        {{- warnf $warningMessage -}}
      {{- end -}}
    {{- end -}}
  {{- end -}}
{{- else -}}
  <!-- Error message if unable to fetch the remote resource -->
  {{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}}
  {{- if eq hugo.Environment "production" -}}
    {{- errorf $message -}}
  {{- else -}}
    {{- warnf $message -}}
  {{- end -}}
{{- end -}}

<!-- Render table only if CVE feed is available, accommodating for offline builds. -->
{{ if and (ne $feed nil) (ne (printf "%T" $feed) "string") }}
<table class="security-cves">
  <caption style="caption-side: top;">{{ T "cve_table" }} {{ printf (T "cve_table_date_format_string") ($feed._kubernetes_io.updated_at | time.Format (T "cve_table_date_format")) }}</caption>
  <thead>
  <tr>
    <th>{{ T "cve_id" }}</th>
    <th>{{ T "cve_summary" }}</th>
    <th>{{ T "cve_issue_url" }}</th>
  </tr>
  </thead>
  <tbody>
  {{ range $feed.items }}
  <tr class="cve-status-{{.status}}">
    <td class="cve-item-id"><a href="{{ .url }}">{{ .id | htmlEscape | safeHTML }}</a></td>
    <td class="cve-item-summary">{{ .summary | htmlEscape | safeHTML }}</td>
    <td><a href="{{ .url }}">#{{ ._kubernetes_io.issue_number }}</a></td>
  </tr>
  {{ end }}
  </tbody>
</table>
{{- end -}}
